
 <!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">
  
    <title>聊一聊去if-else方案 | Typhoon&#39;s code space</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="typhoon">
    

    
    <meta name="description" content="稍微有编程常识的人都知道，if-else分支条件是任何编程语言任何业务中必不可少的环节， 但是过多的if-else分支让代码变得臃肿不可维护，虽然说switch case某种程度上可以替代">
<meta name="keywords" content="去if-else">
<meta property="og:type" content="article">
<meta property="og:title" content="聊一聊去if-else方案">
<meta property="og:url" content="http://scorpioaeolus.oschina.io/2018/07/15/聊一聊去if-else方案/index.html">
<meta property="og:site_name" content="Typhoon&#39;s code space">
<meta property="og:description" content="稍微有编程常识的人都知道，if-else分支条件是任何编程语言任何业务中必不可少的环节， 但是过多的if-else分支让代码变得臃肿不可维护，虽然说switch case某种程度上可以替代">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/15/聊一聊去if-else方案/q2.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/15/聊一聊去if-else方案/q1.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/15/聊一聊去if-else方案/q3.png">
<meta property="og:updated_time" content="2018-08-04T06:30:40.620Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="聊一聊去if-else方案">
<meta name="twitter:description" content="稍微有编程常识的人都知道，if-else分支条件是任何编程语言任何业务中必不可少的环节， 但是过多的if-else分支让代码变得臃肿不可维护，虽然说switch case某种程度上可以替代">
<meta name="twitter:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/07/15/聊一聊去if-else方案/q2.png">

    
    <link rel="alternative" href="/atom.xml" title="Typhoon&#39;s code space" type="application/atom+xml">
    
    
    <link rel="icon" href="/typhoon/img/java.png">
    
    
    <link rel="apple-touch-icon" href="/typhoon/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/typhoon/img/jacman.jpg">
    
    <link rel="stylesheet" href="/typhoon/css/style.css">
</head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/typhoon/"><img src="/typhoon/img/java.png" alt="Typhoon&#39;s code space" title="Typhoon&#39;s code space"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/typhoon/" title="Typhoon&#39;s code space">Typhoon&#39;s code space</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/typhoon/">主页</a></li>
					
						<li><a href="/typhoon/archives">归档</a></li>
					
						<li><a href="/typhoon/about">关于</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:scorpioaeolus.oschina.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/typhoon/2018/07/15/聊一聊去if-else方案/" title="聊一聊去if-else方案" itemprop="url">聊一聊去if-else方案</a>
  </h1>
  <p class="article-author">By
       
		<a href="/typhoon/about" title="typhoon" target="_blank" itemprop="author">typhoon</a>
		
  <p class="article-time">
    <time datetime="2018-07-15T02:58:08.000Z" itemprop="datePublished"> Published 2018-07-15</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#案例一-自定义退货地址问题"><span class="toc-number">1.</span> <span class="toc-text">案例一 自定义退货地址问题</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#案例二-退款类型问题"><span class="toc-number">2.</span> <span class="toc-text">案例二 退款类型问题</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#解决方案"><span class="toc-number">2.1.</span> <span class="toc-text">解决方案</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">3.</span> <span class="toc-text">总结</span></a></li></ol>
		
		</div>
		
		<pre><code>    稍微有编程常识的人都知道，if-else分支条件是任何编程语言任何业务中必不可少的环节，
但是过多的if-else分支让代码变得臃肿不可维护，虽然说switch case某种程度上可以替代
</code></pre><a id="more"></a>
<pre><code>if-else让代码变得调理有序，但是没有从根本上解决问题。那么有没有比较好的方式来解决这
个问题呢？当然是有，我们不妨先看一个案例：
</code></pre><h5 id="案例一-自定义退货地址问题"><a href="#案例一-自定义退货地址问题" class="headerlink" title="案例一 自定义退货地址问题"></a>案例一 自定义退货地址问题</h5><pre><code>1. 背景描述
    会员发起退货退款后，自动化退款逻辑会根据退款信息，所属店铺信息调用自动寻址逻辑，然后把退货地址返回
给会员，但是店铺A突然间提了个需求，对于我店铺A的所有退货退款，退货地址我们自己维护一套，你们退款业务从
退款单中识别到是我A店铺的单子后调用我们自己维护的寻址逻辑，然后返回给会员。

2. 解决方案
    对于1中的需求，我们不考虑扩展性的情况下很好解决，我在同一退货逻辑中加一个if条件判断，通过店铺A给我
的订单标或者店铺id，如果是店铺A的单子我走他们的寻址逻辑，否则走默认的寻址逻辑。用伪代码描述就是：
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">if(退款单属于店铺A) &#123;</div><div class="line">   return 店铺A退货地址	</div><div class="line">&#125; else &#123;</div><div class="line">   return 通用退货地址	</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>3.扩展性
    有一天店铺B发现他们的退货地址库没有入菜鸟仓，也需要我们对其退货地址从通用逻辑剥离单独维护，那么我们
的代码逻辑将变成这样:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">if(退款单属于店铺A) &#123;</div><div class="line">   return 店铺A退货地址	</div><div class="line">&#125; else if(退款单属于店铺B)&#123;</div><div class="line">   return 店铺B退货地址	</div><div class="line">&#125;</div><div class="line">else &#123;</div><div class="line">   return 通用退货地址	</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>    那如果后边有店铺C，店铺D，针织100多家店铺都需要实现这种特殊逻辑，我们将如何维护，如果不想出更好的方
案，那么代码将变成真正的“面条代码”:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">if(退款单属于店铺A) &#123;</div><div class="line">   return 店铺A退货地址	</div><div class="line">&#125; else if(退款单属于店铺B)&#123;</div><div class="line">   return 店铺B退货地址	</div><div class="line">&#125;</div><div class="line">···</div><div class="line">···</div><div class="line">else &#123;</div><div class="line">   return 通用退货地址	</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h5 id="案例二-退款类型问题"><a href="#案例二-退款类型问题" class="headerlink" title="案例二 退款类型问题"></a>案例二 退款类型问题</h5><pre><code>1.背景描述
    在自动化退款流程中，会员发起退款后，逆向交易链路会给我们发送退款消息，自动化退款逻辑会从退款单中识别
或者计算出退款类型，并执行相应的逻辑。如果之前只有仅退款类型，那么如果新业务要支持同意退货怎么办？
2.解决方案
    对于退款类型新增同意退货，那么可以直接在逻辑中增加if判断支持该类型，并调用相应的逻辑。伪代码：
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">	if(退款类型 是 同意退货) &#123;</div><div class="line">	   同意退货</div><div class="line">	&#125; else &#123;</div><div class="line">	   仅退款</div><div class="line">	&#125;</div><div class="line">``` </div><div class="line"></div><div class="line">	3.扩展性</div><div class="line">	    有一天新需求来了，自动化退款要支持同意退货，那么我们仍可以考虑直接加if-else逻辑，代码逻辑将变成这样:</div></pre></td></tr></table></figure>
<pre><code>if(退款类型 是 同意退货) {
   同意退货
} else if(退款类型 是 确认收货) {
   确认收货    
} 
else {
   仅退款
}
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">	    那么后续如果随着业务的发展，需要支持到赔付、换货以及维修等，那么我们将何去何从，继续修改上边的“面条代码”？</div><div class="line"></div><div class="line">```java</div><div class="line">	if(退款类型 是 同意退货) &#123;</div><div class="line">	   同意退货</div><div class="line">	&#125; else if(退款类型 是 确认收货) &#123;</div><div class="line">	   确认收货	</div><div class="line">	&#125; </div><div class="line">	···</div><div class="line">	···</div><div class="line">	else &#123;</div><div class="line">	   仅退款</div><div class="line">	&#125;</div></pre></td></tr></table></figure>
<pre><code>    显然，这种代码是不可维护的，并且如果交给新人接手，估计内心是崩溃的，改没法改，重构鬼才知道中间有没有
什么大坑，整个项目就被这种代码搞得满目疮痍。
</code></pre><h6 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h6><pre><code>对于上述两个问题，在讲述解决方案之前先看下图：
</code></pre><img src="/typhoon/2018/07/15/聊一聊去if-else方案/q2.png" alt="if-else" title="if-else">
<img src="/typhoon/2018/07/15/聊一聊去if-else方案/q1.png" alt="if-else" title="if-else">
<pre><code>    从两张图中我们大概可以看出几个关键的点：
1）请求上下文信息中一定要有一个能够抽象出来有辨识度的属性（比如退款类型，或者店铺id）
2）一定要有一个地方存储1）中有辨识度的属性与我们自己定义的执行器的标签的映射关系（配置中心或者DB）    
3）要有一个容器存储所有自定义执行器(和spring容器中其他bean隔离)，并且能够根据标签获取到响应的执行器

    基于以上描述，我们已经有了方案，接下来分别针对退货地址案例给出具体的实现方案。


退货地址接口：
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line"> * 寻址接口</div><div class="line"> */</div><div class="line">public interface ReturnAddressService &#123;</div><div class="line"></div><div class="line">    String getAddress(Long sellerId);</div><div class="line"></div><div class="line">    String getCode();</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>退货地址接口抽象实现:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line"> * 自定义寻址抽象实现</div><div class="line"> */</div><div class="line">public abstract class AbstractReturnAddressService implements ReturnAddressService &#123;</div><div class="line"></div><div class="line">    @Override</div><div class="line">    public String getAddress(Long sellerId) &#123;</div><div class="line">        if(null == sellerId) &#123;</div><div class="line">            throw new IllegalArgumentException(&quot;params is illegal&quot;);</div><div class="line">        &#125;</div><div class="line">        return execute(sellerId);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    public abstract String execute(Long sellerId);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>店铺A自定义寻址实现：
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line"> * 店铺A自定义寻址</div><div class="line"> */</div><div class="line">@Service(&quot;storeAReturnAddressService&quot;)</div><div class="line">public class StoreAReturnAddressServiceImpl extends  AbstractReturnAddressService &#123;</div><div class="line"></div><div class="line"></div><div class="line">    @Override</div><div class="line">    public String execute(Long sellerId) &#123;</div><div class="line">        return &quot;店铺A退货地址&quot;;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    @Override</div><div class="line">    public String getCode() &#123;</div><div class="line">        return StoreReturnAddressEnum.STORE_A.getCode();</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>店铺B自定义寻址实现：
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line"> * 店铺B自定义寻址</div><div class="line"> */</div><div class="line">@Service(&quot;storeBReturnAddressService&quot;)</div><div class="line">public class StoreBReturnAddressServiceImpl extends AbstractReturnAddressService &#123;</div><div class="line">    @Override</div><div class="line">    public String execute(Long sellerId) &#123;</div><div class="line">        return &quot;店铺B退货地址&quot;;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    @Override</div><div class="line">    public String getCode() &#123;</div><div class="line">        return StoreReturnAddressEnum.STORE_B.getCode();</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>自定义寻址执行器容器:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line"> * 自定义寻址容器</div><div class="line"> */</div><div class="line">@Component</div><div class="line">public class CustomReturnAddressHolder implements ApplicationContextAware &#123;</div><div class="line"></div><div class="line">    private static Map&lt;String,ReturnAddressService&gt; map = new HashMap&lt;&gt;();</div><div class="line"></div><div class="line">    /**</div><div class="line">     * 初始化容器</div><div class="line">     *</div><div class="line">     * @param applicationContext</div><div class="line">     * @throws BeansException</div><div class="line">     */</div><div class="line">    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException &#123;</div><div class="line">        if(null != applicationContext) &#123;</div><div class="line">            Map&lt;String,ReturnAddressService&gt; beans = applicationContext.getBeansOfType(ReturnAddressService.class);</div><div class="line">            if(null != beans &amp;&amp; !beans.isEmpty()) &#123;</div><div class="line">                beans.forEach((k,v) -&gt; &#123;</div><div class="line">                    map.put(v.getCode(),v);</div><div class="line">                &#125;);</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * 获取自定义执行器</div><div class="line">     *</div><div class="line">     * @param code</div><div class="line">     * @return</div><div class="line">     */</div><div class="line">    public ReturnAddressService getByCode(String code) &#123;</div><div class="line">        return map.get(code);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>店铺与执行器code映射关系（暂用本地map代替）:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"> static Map&lt;String,String&gt; map = new HashMap&lt;&gt;();</div><div class="line">static &#123;</div><div class="line">	//店铺与执行器映射关系</div><div class="line">	map.put(StoreReturnAddressEnum.STORE_A.getCode(),&quot;store_a&quot;);</div><div class="line">	map.put(StoreReturnAddressEnum.STORE_B.getCode(),&quot;store_b&quot;);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>测试验证代码:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">public static void main(String[] args) &#123;</div><div class="line">		AbstractApplicationContext context = new ClassPathXmlApplicationContext(&quot;spring-root.xml&quot;);</div><div class="line">		CustomReturnAddressHolder returnAddressHolder = context.getBean(&quot;customReturnAddressHolder&quot;,CustomReturnAddressHolder.class);</div><div class="line">		String storeA = &quot;store_a&quot;;</div><div class="line">		String storeB = &quot;store_b&quot;;</div><div class="line">		String executorCodeA = null;</div><div class="line">		String executorCodeB = null;</div><div class="line">		for(Map.Entry&lt;String,String&gt; entry : map.entrySet()) &#123;</div><div class="line">			if(entry.getValue().equals(storeA)) &#123;</div><div class="line">				executorCodeA = entry.getKey();</div><div class="line">				continue;</div><div class="line">			&#125;</div><div class="line">			if(entry.getValue().equals(storeB)) &#123;</div><div class="line">				executorCodeB = entry.getKey();</div><div class="line">			&#125;</div><div class="line">		&#125;</div><div class="line">		ReturnAddressService storeAService = returnAddressHolder.getByCode(executorCodeA);</div><div class="line">		ReturnAddressService storeBService = returnAddressHolder.getByCode(executorCodeB);</div><div class="line">		System.out.println(storeAService.getAddress(1L));</div><div class="line">		System.out.println(storeBService.getAddress(2L));</div><div class="line">	&#125;</div></pre></td></tr></table></figure>
<pre><code>运行测试代码：
</code></pre><img src="/typhoon/2018/07/15/聊一聊去if-else方案/q3.png" alt="if-else" title="if-else">
<pre><code>    根据运行结果，我们看到已经通过利用spring自定义容器加上执行器自带code取巧方案，我们已经实现了消除
if-else代码的初衷。并且如果扩展店铺C只需要增加自定义执行器即可，完全不需要修改业务逻辑和容器逻辑，也
就实现了执行器和业务逻辑剥离，更高一层也即是业务域和底层平台调用链剥离，从而使我们的业务和代码都变得
清晰有致。当然这只是简单的实现了if-else逻辑的消除，阿里内部平台基本都是用了TMF的架构模式，其本质上的
原理也是自定义执行器，自定义扩展点，动态加载。至于TMF框架，阿里暂没有开源，想了解的话暂时优点困难。
</code></pre><h5 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h5><pre><code>    通过上述一系列描述，我们简单实现了使用业务执行器自定义扩展点的方式去除繁杂的if-else逻辑，希望在日
常开发和学习中对大家有帮助，如果感兴趣可以私聊我，共同探讨共同进步。
</code></pre>  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/typhoon/categories/案例分析/">案例分析</a>
</div>


  <div class="article-tags">
  
  <span></span> <a href="/typhoon/tags/去if-else/">去if-else</a>
  </div>

</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://scorpioaeolus.oschina.io/2018/07/15/聊一聊去if-else方案/" data-title="聊一聊去if-else方案 | Typhoon&#39;s code space" data-tsina="null" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/typhoon/2018/07/22/聊一聊基于业务场景的重试及实现/" title="聊一聊基于业务场景的重试及实现">
  <strong>上一篇：</strong><br/>
  <span>
  聊一聊基于业务场景的重试及实现</span>
</a>
</div>


<div class="next">
<a href="/typhoon/2018/07/14/dubbo服务两种方式打包部署到阿里云/"  title="dubbo服务两种方式打包部署到阿里云">
 <strong>下一篇：</strong><br/> 
 <span>dubbo服务两种方式打包部署到阿里云
</span>
</a>
</div>

</nav>

	


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#案例一-自定义退货地址问题"><span class="toc-number">1.</span> <span class="toc-text">案例一 自定义退货地址问题</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#案例二-退款类型问题"><span class="toc-number">2.</span> <span class="toc-text">案例二 退款类型问题</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#解决方案"><span class="toc-number">2.1.</span> <span class="toc-text">解决方案</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">3.</span> <span class="toc-text">总结</span></a></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/typhoon/categories/dubbo/" title="dubbo">dubbo<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java性能优化/" title="java性能优化">java性能优化<sup>17</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java源码分析/" title="java源码分析">java源码分析<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/motan/" title="motan">motan<sup>2</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/spring/" title="spring">spring<sup>11</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springboot/" title="springboot">springboot<sup>28</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springmvc/" title="springmvc">springmvc<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/容器/" title="容器">容器<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/工具/" title="工具">工具<sup>7</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/性能优化/" title="性能优化">性能优化<sup>5</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/架构/" title="架构">架构<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/案例分析/" title="案例分析">案例分析<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/缓存/" title="缓存">缓存<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/面试题/" title="面试题">面试题<sup>1</sup></a></li>
		  
		
		</ul>
</div>


  
<div class="tagslist">
	<p class="asidetitle">Tags</p>
		<ul class="clearfix">
		
			
				<li><a href="/typhoon/tags/springboot/" title="springboot">springboot<sup>28</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/java性能优化/" title="java性能优化">java性能优化<sup>9</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/限流/" title="限流">限流<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring5/" title="Spring5">Spring5<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/案例分析/" title="案例分析">案例分析<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/性能优化/" title="性能优化">性能优化<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring/" title="Spring">Spring<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo/" title="dubbo">dubbo<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/分页/" title="分页">分页<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/并发/" title="并发">并发<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/异常拦截/" title="异常拦截">异常拦截<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo分布式事务/" title="dubbo分布式事务">dubbo分布式事务<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/自带图片/" title="自带图片">自带图片<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/svn导出mvn项目/" title="svn导出mvn项目">svn导出mvn项目<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo过滤器/" title="dubbo过滤器">dubbo过滤器<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/排序性能对比/" title="排序性能对比">排序性能对比<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/ListenableFuture/" title="ListenableFuture">ListenableFuture<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/PropertyChangeListener/" title="PropertyChangeListener">PropertyChangeListener<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/jdbcTemplate高可用/" title="jdbcTemplate高可用">jdbcTemplate高可用<sup>1</sup></a></li>
			
		
		</ul>
</div>


  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=null&verifier=b3593ceb&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m a java coder. <br/>
			This is my blog,believe it or not.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
		<a href="mailto:ScorpioAeolus@163.com" target="_blank" class="icon-email" title="Email Me"></a>
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2019 
		
		<a href="/typhoon/about" target="_blank" title="typhoon">typhoon</a>
		
		
		</p>
</div>
</footer>
    <script src="/typhoon/js/jquery-2.0.3.min.js"></script>
<script src="/typhoon/js/jquery.imagesloaded.min.js"></script>
<script src="/typhoon/js/gallery.js"></script>
<script src="/typhoon/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>









<link rel="stylesheet" href="/typhoon/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/typhoon/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/typhoon/img/scrollup.png"/></a>
	</div>
	<script src="/typhoon/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
